package com.dubito.github.user.fragment

import com.dubito.github.R
import com.dubito.github.base.fragment.BaseDataBindViewModelFragment
import com.dubito.github.base.viewmodel.BaseViewModel
import com.dubito.github.databinding.FragmentUserInfoBinding
import com.dubito.github.user.activity.UserInfoActivity
import com.dubito.github.user.viewmodel.UserViewModel
import kotlinx.android.synthetic.main.fragment_user_info.*
import org.koin.androidx.viewmodel.ext.android.viewModel

/**
 *@Author: liliang
 *@Date: 2020/8/6 6:28 PM
 *
 */
class UserInfoFragment : BaseDataBindViewModelFragment<FragmentUserInfoBinding>() {


    private val mViewModel: UserViewModel by viewModel()

    override fun getViewModel(): BaseViewModel = mViewModel

    override fun getLayoutRes(): Int = R.layout.fragment_user_info

    private lateinit var mUser: String

    override fun initView() {
        mUser = (activity as UserInfoActivity).mUserModel.login
        mSwipeRefreshLayout.setOnRefreshListener {
            initData()
        }
    }

    override fun showLoading() {
        mSwipeRefreshLayout.isRefreshing = true
    }

    override fun dismissLoading() {
        mSwipeRefreshLayout.isRefreshing = false
    }

    override fun initData() {
        dataBind.userViewModel = mViewModel
        mViewModel.getUserInfo(mUser)
    }
}